import wx

"""

"""


class RefactorExample(wx.Frame):

    def __init__(self, parent, id):
        super().__init__(parent, id, "Refactor Example", size=(340, 200))

        panel = wx.Panel(self, -1)
        panel.SetBackgroundColour("White")
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

        self.CreateButtonBar(panel, 5)
        self.CreateStatusBar()
        self.SetMenuBar(self.CreateMenuBar())
        self.CreateTextFields(panel)

    def ButtonData(self):
        return (("FIRST", self.OnFirst),
                ("<<PREV", self.OnPrev),
                ("NEXT>>", self.OnNext),
                ("LAST", self.OnLast))

    def MenuDada(self):
        return (("File",
                 ("Open", "Open in Status bar", self.OnOpen),
                 ("Quit", "Quit", self.OnCloseWindow)),
                ("Edit",
                 ("Copy", "Copy", self.OnCopy),
                 ("Cut", "Cut", self.OnCut),
                 ("Paste", "Paste", self.OnPaste),
                 ("", "", ""),
                 ("Options...", "DisplayOptions", self.OnOptions)))

    def TextFieldData(self):
        return (
            ("Firss Name:", (10, 50), "While", ("", (85, 50), (100, -1))),
            ("Last Name:", (10, 80), "While", ("", (85, 80), (100, -1))))

    def CreateButtonBar(self, parent, yPos=0):
        xPos = 5
        buttons = []

        for eachLabel, eachHandler in self.ButtonData():
            pos = (xPos, yPos)
            button = self.BuildOneButton(parent, eachLabel, eachHandler, pos)
            xPos += button.GetSize().width + 5
            buttons.append(button)

        return buttons

    def CreateMenuBar(self):
        menuBar = wx.MenuBar()
        for data in self.MenuDada():
            menuLabel = data[0]
            menuItem = data[1:]
            menuBar.Append(self.CreateMenu(menuItem), menuLabel)

        return menuBar

    def CreateTextFields(self, parent):
        for data in self.TextFieldData():
            self.createCaptionedText(parent,data)

    def createCaptionedText(self, parent, data):
        for e in data:
            text = wx.StaticText(parent, -1, data[0], pos=data[1])
            text.SetBackgroundColour(data[2])
            wx.TextCtrl(parent, -1, data[3][0], pos=data[3][1], size=data[3][2])

    def CreateMenu(self, menuData):
        menu = wx.Menu()
        for eachLabel, eachStatus, eachHandler in menuData:
            if not eachLabel:
                menu.AppendSeparator()
            else:
                menuItem = menu.Append(-1, eachLabel, eachStatus)
                self.Bind(wx.EVT_MENU, eachHandler, menuItem)
        return menu

    def BuildOneButton(self, parent, label, handler, pos=(0, 0)):
        button = wx.Button(parent, -1, label, pos)
        self.Bind(wx.EVT_BUTTON, handler, button)
        return button

    # Just grouping the empty event handlers together
    def OnPrev(self, event):
        pass

    def OnNext(self, event):
        pass

    def OnLast(self, event):
        pass

    def OnFirst(self, event):
        pass

    def OnOpen(self, event):
        pass

    def OnCopy(self, event):
        pass

    def OnCut(self, event):
        pass

    def OnPaste(self, event):
        pass

    def OnOptions(self, event):
        pass

    def OnCloseWindow(self, event):
        self.Destroy()


if __name__ == '__main__':
    app = wx.App()

    frame = RefactorExample(None, -1)
    frame.Show()

    app.MainLoop()
